<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Class: RestAPI</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Class: RestAPI</h1>

    




<section>

<header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>RestAPI<span class="signature">(address<span class="signature-attributes">non-null</span>)</span><span class="type-signature"> &rarr; {<a href="RestAPI.html">RestAPI</a>}</span></h2>
        
    
</header>

<article>
    <div class="container-overview">
    
        

    

    
    <h4 class="name" id="RestAPI"><span class="type-signature"></span>new RestAPI<span class="signature">(address<span class="signature-attributes">non-null</span>)</span><span class="type-signature"> &rarr; {<a href="RestAPI.html">RestAPI</a>}</span></h4>
    

    



<div class="description">
    Creates an instance of RestAPI.
<br />
与RepChain网络节点交互的Restful API客户端.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>address</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">RepChain节点Restful API服务地址</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line15">line 15</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    RestAPI对象实例
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="RestAPI.html">RestAPI</a></span>


    </dd>
</dl>

    





    
    </div>

    

    

    

    

    

    

    

    
        <h3 class="subsection-title">Methods</h3>

        
            

    

    
    <h4 class="name" id="block"><span class="type-signature"></span>block<span class="signature">(id, blockFormat<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Object>|Promise.&lt;Buffer>}</span></h4>
    

    



<div class="description">
    获取区块数据
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>id</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>
|

<span class="param-type">Buffer</span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            
                <td class="default">
                
                </td>
            

            <td class="description last">区块唯一标识，可为区块高度(number)或区块哈希值(base64编码字符串或二进制数据)</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>blockFormat</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    "JSON"
                
                </td>
            

            <td class="description last">期望返回的区块数据的格式，可为JSON或STREAM</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line104">line 104</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    区块数据
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;Object></span>
|

<span class="param-type">Promise.&lt;Buffer></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="chainCurrentBlockHash"><span class="type-signature"></span>chainCurrentBlockHash<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4>
    

    



<div class="description">
    获取最新区块哈希值
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line62">line 62</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    区块哈希值(base64编码字符串)
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;string></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="chainCurrentStateHash"><span class="type-signature"></span>chainCurrentStateHash<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4>
    

    



<div class="description">
    获取当前的世界状态哈希值
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line82">line 82</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    世界状态哈希值(base64编码字符串)
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;string></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="chainHeight"><span class="type-signature"></span>chainHeight<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;number>}</span></h4>
    

    



<div class="description">
    获取区块链最新区块高度
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line52">line 52</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    区块高度
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;number></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="chainInfo"><span class="type-signature"></span>chainInfo<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;ChainInfo>}</span></h4>
    

    



<div class="description">
    获取区块链的当前概要信息
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line37">line 37</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    Json格式信息<a href="RestAPI.html#.ChainInfo">ChainInfo</a>
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;ChainInfo></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="chainPreviousBlockHash"><span class="type-signature"></span>chainPreviousBlockHash<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4>
    

    



<div class="description">
    获取最新区块的父区块哈希值
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line72">line 72</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    最新区块的父区块哈希值(base64编码字符串)
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;string></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="chainTotalTransactions"><span class="type-signature"></span>chainTotalTransactions<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;number>}</span></h4>
    

    



<div class="description">
    获取区块链中的交易总数量
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line92">line 92</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    交易总量
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;number></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="sendTransaction"><span class="type-signature"></span>sendTransaction<span class="signature">(tx)</span><span class="type-signature"> &rarr; {Promise.&lt;{txid: string}>|Promise.&lt;{err: string}>}</span></h4>
    

    



<div class="description">
    发送签名交易
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tx</code></td>
            

            <td class="type">
            
                
<span class="param-type">Buffer</span>
|

<span class="param-type">String</span>


            
            </td>

            

            

            <td class="description last">待发送的已签名交易数据，支持使用Buffer类型数据或其hex编码的String数据</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line160">line 160</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    接收交易后RepChain节点的返回信息
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;{txid: string}></span>
|

<span class="param-type">Promise.&lt;{err: string}></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="transaction"><span class="type-signature"></span>transaction<span class="signature">(id, txFormat<span class="signature-attributes">opt</span>, withBlockHeight<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Object>|Promise.&lt;Buffer>}</span></h4>
    

    



<div class="description">
    获取交易数据
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>id</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            
                <td class="default">
                
                </td>
            

            <td class="description last">交易唯一标识，即txid</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>txFormat</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    "JSON"
                
                </td>
            

            <td class="description last">期望返回的交易数据的格式</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>withBlockHeight</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    false
                
                </td>
            

            <td class="description last">返回交易数据中是否包含区块高度，当txFormat="JSON"时才有效</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line135">line 135</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        


<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise.&lt;Object></span>
|

<span class="param-type">Promise.&lt;Buffer></span>


    </dd>
</dl>

    





        
    

    
        <h3 class="subsection-title">Type Definitions</h3>

        
                
<h4 class="name" id=".ChainInfo">ChainInfo</h4>




<div class="description">
    区块链的概要信息
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Object</span>


        </li>
    </ul>





    <h5 class="subsection-title">Properties:</h5>

    

<table class="props">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>height</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">最新区块高度</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>currentBlockHash</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">最新区块哈希值(base64编码字符串)</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>previousBlockHash</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">最新区块的父区块哈希值(base64编码字符串)</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>currentStateHash</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">世界状态哈希值(base64编码字符串)</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>totalTransactions</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">交易总量</td>
        </tr>

    
    </tbody>
</table>




<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rest.js.html">rest.js</a>, <a href="rest.js.html#line20">line 20</a>
    </li></ul></dd>
    

    

    

    
</dl>






            
    

    
</article>

</section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="EventTube.html">EventTube</a></li><li><a href="RestAPI.html">RestAPI</a></li><li><a href="Transaction.html">Transaction</a></li></ul><h3>Global</h3><ul><li><a href="global.html#CalculateAddr">CalculateAddr</a></li><li><a href="global.html#CreateCertificate">CreateCertificate</a></li><li><a href="global.html#CreateCSR">CreateCSR</a></li><li><a href="global.html#CreateKeypair">CreateKeypair</a></li><li><a href="global.html#CreateSelfSignedCertificate">CreateSelfSignedCertificate</a></li><li><a href="global.html#GetCSRInfoFromPEM">GetCSRInfoFromPEM</a></li><li><a href="global.html#GetHashVal">GetHashVal</a></li><li><a href="global.html#GetKeyPEM">GetKeyPEM</a></li><li><a href="global.html#ImportCertificate">ImportCertificate</a></li><li><a href="global.html#ImportKey">ImportKey</a></li><li><a href="global.html#Sign">Sign</a></li><li><a href="global.html#VerifyCertificateSignature">VerifyCertificateSignature</a></li><li><a href="global.html#VerifySign">VerifySign</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Sep 27 2020 14:29:27 GMT+0800 (China Standard Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>